﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace ZBZH_Manage_Order.PublicMethod
{
    public class WriteLog
    {
        #region 定义变量
        #endregion
        #region 系统日记记录(带文件名)
        public static void WriteErrLog(string strErrMod, string strErrDesc)
        {
            try
            {
                StreamWriter sw;
                string strErrLog = ".\\gErr.txt";
                //App.Current.Host.Source.AbsoluteUri + @"gErr.txt";
                //System.AppDomain.CurrentDomain.AssemblyResolve().Location + @"gErr.txt";   //获取写日志的路径
                if (File.Exists(strErrLog))
                {
                    FileInfo oFile = new FileInfo(strErrLog);
                    if (oFile.Length > 1024000)
                    {
                        oFile.Delete();
                    }
                }
                if (File.Exists(strErrLog))
                {
                    sw = File.AppendText(strErrLog);
                }
                else
                {
                    sw = File.CreateText(strErrLog);
                }
                string strDate = "出错时间:" + string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
                string strErrMoudle = "出错模块:" + strErrMod;
                string strErrDescOut = "错误原因:" + strErrDesc;
                sw.WriteLine(strDate);
                sw.WriteLine(strErrMoudle);
                sw.WriteLine(strErrDescOut);
                sw.WriteLine("===================================================================");
                sw.Flush();
                sw.Close();
            }
            catch (Exception)
            {

            }

        }
        #endregion
    }
}